package com.ylx.web.s;

import com.alibaba.fastjson.JSON;
import com.ylx.pojo.Goods;
import com.ylx.pojo.PageBean;
import com.ylx.service.GoodsService;
import com.ylx.service.GoodsServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/selectByPageServlet")
public class SelectByPageServlet extends HttpServlet {
      private GoodsService goodsService=new GoodsServiceImpl();
    protected void doPost (HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        String _currentPage = request.getParameter("currentPage");
        String _pageSize = request.getParameter("pageSize");
        int currentPage = Integer.parseInt(_currentPage);
        int pageSize = Integer.parseInt(_pageSize);

        PageBean<Goods> pageBean = goodsService.selectByPage(currentPage, pageSize);

        String jsonString=JSON.toJSONString(pageBean);

        response.setContentType("text/json;charset=utf-8");
        response.getWriter().write(jsonString);










    }

    protected void doGet (HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        this.doPost(request, response);

    }
}
